package com.ruoyi.web.controller.employee;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.HfScheme;
import com.ruoyi.employee.service.IHfSchemeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公积金方案Controller
 *
 * @author hango
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/staffinfo/hfScheme")
public class HfSchemeController extends BaseController
{
    @Autowired
    private IHfSchemeService hfSchemeService;

    /**
     * 查询公积金方案列表
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(HfScheme hfScheme)
    {
        startPage();
        List<HfScheme> list = hfSchemeService.selectHfSchemeList(hfScheme);
        return getDataTable(list);
    }

    /**
     * 导出公积金方案列表
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:export')")
    @Log(title = "公积金方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HfScheme hfScheme)
    {
        List<HfScheme> list = hfSchemeService.selectHfSchemeList(hfScheme);
        ExcelUtil<HfScheme> util = new ExcelUtil<HfScheme>(HfScheme.class);
        util.exportExcel(response, list, "公积金方案数据");
    }

    /**
     * 获取公积金方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hfSchemeService.selectHfSchemeById(id));
    }

    /**
     * 新增公积金方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:add')")
    @Log(title = "公积金方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HfScheme hfScheme)
    {
        return toAjax(hfSchemeService.insertHfScheme(hfScheme));
    }

    /**
     * 修改公积金方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:edit')")
    @Log(title = "公积金方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HfScheme hfScheme)
    {
        return toAjax(hfSchemeService.updateHfScheme(hfScheme));
    }

    /**
     * 删除公积金方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:hfScheme:remove')")
    @Log(title = "公积金方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        // ★ 关键：这里也是 Long[]，保证从 Controller 开始就是 Long[]
        return toAjax(hfSchemeService.deleteHfSchemeByIds(ids));
    }
}
